<!--
 * @Description: 销售记录
 *
 * @Author: guichengcai<guichengcai>
 * @Date: 2023-07-03 17:11:54
 * @FilePath: /yuxiuproweb/src/views/reportforms/sale/index.vue
-->
<template>
  <div class="app-container">
    <el-form
      :model="queryParams"
      ref="queryForm"
      size="small"
      :inline="true"
      v-show="showSearch"
      label-width="68px"
    >
      <el-form-item label="订单编号" prop="orderId">
        <el-input
          v-model="queryParams.orderId"
          placeholder="请输入订单编号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="客户名称" prop="clientName">
        <el-input
          v-model="queryParams.clientName"
          placeholder="请输入客户名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
		<el-form-item label="省份" prop="province">
		  <el-input
		    v-model="queryParams.province"
		    placeholder="请输入省份"
		    clearable
		    @keyup.enter.native="handleQuery"
		  />
		</el-form-item>
		<el-form-item label="品牌" prop="brandId">
		  <el-select
		    style="width: 100%"
		    v-model="queryParams.brandId"
		    filterable
		    placeholder="请选择品牌"
		  >
		    <el-option
		      v-for="item in brandList"
		      :key="item.brandId"
		      :label="item.brandName"
		      :value="item.brandId"
		    >
		    </el-option>
		  </el-select>
		</el-form-item>
				<el-form-item label="下单时间" prop="createDate">
				  <el-date-picker
				    align="center"
				    style="width: 240px"
				    v-model="queryParams.createDateObj"
				    type="daterange"
				    range-separator="至"
				    start-placeholder="开始日期"
				    end-placeholder="结束日期"
				    value-format="yyyy-MM-dd"
				    format="yyyy-MM-dd"
				  >
				  </el-date-picker>
				</el-form-item>
      <el-form-item>
        <el-button
          type="primary"
          icon="el-icon-search"
          size="mini"
          @click="handleQuery"
          >搜索</el-button
        >
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery"
          >重置</el-button
        >
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['pro:record:export']"
          >导出</el-button
        >
      </el-col>
      <right-toolbar
        :showSearch.sync="showSearch"
        @queryTable="getList"
      ></right-toolbar>
    </el-row>

    <el-table
      v-loading="loading"
      :data="recordList"
      @selection-change="handleSelectionChange"
      :max-height="maxHeight"
    >
      <el-table-column type="selection" width="55" align="center" />
      <!-- <el-table-column
        label="现金账户扣减"
        align="center"
        prop="transactionRecordId"
      /> -->
      <el-table-column label="采购订单号" align="center" prop="arrivalNoteNumber" />
      <el-table-column label="日期" align="center" prop="arrivalDate" />
	  <el-table-column label="供应商" align="center" prop="supplierId" />
	  <el-table-column label="部门" align="center" min-width="100" prop="deptName"/>
      <el-table-column label="状态" align="center" prop="client_name" />
			<el-table-column label="预警状态" align="center" prop="client_name" />
	  <el-table-column label="备注" align="center" prop="name" />
		<el-table-column label="到料日期" align="center" prop="name" />
      <el-table-column label="存货编码" align="center" prop="detail" />
      <el-table-column label="型号" align="center" prop="subtotal" />

	  <el-table-column label="数量" align="center" prop="subtotal" />
	  <el-table-column label="到货量" align="center" prop="subtotal" />
	  <el-table-column label="未到货量" align="center" prop="subtotal" />
	  <el-table-column label="验布[未检]" align="center" prop="subtotal" />
	  <el-table-column label="入库量" align="center" prop="subtotal" />
	  <el-table-column label="退货量" align="center" prop="subtotal" />
	  <el-table-column label="实际入库量" align="center" prop="subtotal" />
	  <el-table-column label="预计到货日期" align="center" prop="subtotal" />
      <el-table-column label="来源单号" align="center" prop="subtotal" />
	  <el-table-column label="来源类型" align="center" prop="subtotal" />
	  <el-table-column label="申购类型" align="center" prop="subtotal" />
	  <el-table-column label="制单人" align="center" prop="subtotal" />
	  <el-table-column label="审核人" align="center" prop="subtotal" />
	  <el-table-column label="是否关闭" align="center" prop="subtotal" />
	  </el-table-column>
    </el-table>

    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

  </div>
</template>

<script>
import {
  listRecord,
  getRecord,
  delRecord,
  addRecord,
  updateRecord,
} from "@/api/buys/qbbuyorder";
import commonMix from "@/utils/mixins/common";

export default {
  mixins: [commonMix],
  name: "Record",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 交易记录表格数据
      recordList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 100,
        orderId: null,
        clientId: null,
        clientName: null,
        cashAccount: null,
        rebateAccount: null,
        otherAccount: null,
      },
	  brandList: [],
      // 表单参数
      form: {},
      // 表单校验
      rules: {},
    };
  },
  // get_brand_name(brand_id){
	 // if(brand_id==1){
		//  return '有点牛';
	 // }
  // },
  created() {
    this.getList();
	this.getBrandList();
  },
  methods: {
    /** 查询交易记录列表 */
    getList() {
      this.loading = true;
	  const params = {
	    ...this.queryParams,
	    startDate: this.queryParams.createDateObj?.[0] || null,
	    endDate: this.queryParams.createDateObj?.[1] || null,
	  };
	  delete params.createDateObj;
      listRecord(params).then((response) => {
        this.recordList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        transactionRecordId: null,
        orderId: null,
        clientId: null,
        clientName: null,
        cashAccount: null,
        rebateAccount: null,
        otherAccount: null,
        createBy: null,
        createTime: null,
        updateBy: null,
        updateTime: null,
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map((item) => item.transactionRecordId);
      this.single = selection.length !== 1;
      this.multiple = !selection.length;
    },
   getBrandList() {
     listBrand({
       pageNum: 1,
       pageSize: 500,
     }).then(({ rows }) => {
       this.brandList = rows;
       console.log(this.brandList);
     });
   },

    /** 导出按钮操作 */
    handleExport() {
      this.download(
        "statistic/export",
        {
          ...this.queryParams,
        },
        `record_${new Date().getTime()}.xlsx`
      );
    },
  },
};
</script>
